package com.diudiutechnology.www.yadiudiu.yadiudiu.house.MyActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter.BannersAdapter;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 2017/8/15.
 * 购车详情
 */

public class RentDetailsActivity extends Activity implements OnClickListener {
    @Bind(R.id.title_center)
    TextView titlecenter;
    @Bind(R.id.retur)
    LinearLayout retur;
    @Bind(R.id.ad_pager)
    ViewPager adPager;
    @Bind(R.id.ad_text)
    TextView adtext;
    @Bind(R.id.contact)
    TextView contact;
    @Bind(R.id.rent)
    TextView rent;
    private final int HOME_AD_RESULT = 1;
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                // 广告
                case HOME_AD_RESULT:
                    adPager.setCurrentItem(adPager.getCurrentItem() + 1,
                            true);
                    break;
            }
        }

        ;
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rent_details);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        titlecenter.setText("详情");
        rent.setText(Html.fromHtml("租金：<font color='#FD1142'>1,000元/月</font>（押1付3）"));
        retur.setOnClickListener(this);
        contact.setOnClickListener(this);
        List<String> getinforresult = new ArrayList<>();
        getinforresult.add("1");
        getinforresult.add("1");
        getinforresult.add("1");
        getadvertising(getinforresult.size(), getinforresult);
    }

    //轮播广告
    public void getadvertising(final int size, final List<String> getinforresult) {
        adPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                adtext.setText((position % size + 1) + "/" + size);
                // Sundry.refreshPoint(ad_layer,position % size,0);
                if (mHandler.hasMessages(HOME_AD_RESULT)) {
                    mHandler.removeMessages(HOME_AD_RESULT);
                }
                mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3 * 1000);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                if (ViewPager.SCROLL_STATE_DRAGGING == arg0
                        && mHandler.hasMessages(HOME_AD_RESULT)) {
                    mHandler.removeMessages(HOME_AD_RESULT);
                }
            }
        });
        BannersAdapter adapter = new BannersAdapter(this, getinforresult, 1);
        adPager.setAdapter(adapter);
        //Sundry.initPointsLayout(ad_layer,this,size,0);
        adPager.setCurrentItem(size * 1000, false);
        // 自动轮播线程
        mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3 * 1000);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.retur:
                finish();
                break;
            case  R.id.contact:
                startActivity(new Intent(RentDetailsActivity.this,PaymentActivity.class));


                break;
        }
    }
}
